// pages/knowledge/classify/classifylist.js
var t = getApp(), e = t.requirejs("core"), a = t.requirejs("jquery"), s = t.requirejs("biz/diyform"), i = t.requirejs("biz/goodspicker");

t.requirejs("foxui");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    index:-1,
    id:-1,
    page:1,
    allgoods:[]
  },
  classifylist(e){
    console.log(e)
    var id = e.currentTarget.dataset.id
    var that =this;
    that.setData({
      id: id,
      allgoods:[],
    }),that.getList(id,1);
  },
  musicurl(e) {
    clearInterval(this.data.durationIntval1);
    wx.setStorageSync('audioSeek', this.data.audioSeek);
    this.setData({
      audioSeek: '',
    })

    var id = wx.getStorageSync('id');
    var type = wx.getStorageSync('type')
    wx.navigateTo({
      url: '/pages/knowledge/videoknow/index?id=' + id + '&type=' + type,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var s = this;
    e.fromsearch;
    var id = options.id;
    s.setData({
      id:id
    }), this.initCategory()

  },
  onShow:function(){
    var t =this;
    var isPlayAudio = wx.getStorageSync('isPlayAudio');
    var audioSeek = wx.getStorageSync('audioSeek');
    var id = wx.getStorageSync('id');
    console.log(isPlayAudio, 7878)
    if (isPlayAudio == true) {
      this.data.durationIntval1 = setInterval(function () {
        if (t.data.audioSeek == null || t.data.audioSeek == '') {
          var seek = audioSeek;
        } else {
          var seek = t.data.audioSeek;
        }
        t.setData({
          audioSeek: seek + 1
        })
        wx.setStorageSync('audioSeek', seek + 1)
      }, 1000)
    } else {
      clearInterval(this.data.durationIntval1);
    }
    t.setData({
      isPlayAudio: isPlayAudio
    })
  },
  // onUnload:function(){

  // },
  initCategory: function () {
    var t = this;
    var page = t.data.page;
     console.log(t,888);
    e.get("goods/get_categoryknow", {}, function (e) {
 
      t.setData({
        allcategory: e.allcategory,
       
      });
    }),
    console.log(t.data.id,3434)
    t.getList(t.data.id,);
  },
  getList:function(option,page)
  {
    var that = this;
    var cateid= option;
    var page = that.data.page;
    console.log(page,4444);
    e.get("goods/get_listknow2", {cateid:cateid,page:page}, function (e) {
      console.log(that.data.list, 777, e.list.list, 8888, that.data.allgoods.concat(e.list.list));
      var allgoods = that.data.allgoods.concat(e.list.list)
      for (var i = 0; i < allgoods.length;i++){
        if (Number(allgoods[i].marketprice)==0){
          allgoods[i].marketprice = 0 
        }
      }
      // console.log(allgoods,8989);
      that.setData({
        allgoods: allgoods,
        cateid:cateid,
        page:page,

      });
    })
  },
  onPullDownRefresh: function () {
    console.log(this,123);
    var page = this.data.page;
    var newpage = page+1;
    var cateid = this.data.cateid;
    
    //var name = this.data.categorys[this.data.flag];
    this.setData({
      // flag: 0,
      page: newpage,
      clickloadshow: !0
    });
    this.getList(cateid,newpage);
    // 隐藏导航栏加载框
    wx.hideNavigationBarLoading();
    // 停止下拉动作
    wx.stopPullDownRefresh();
  },

 
})